home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / LDEFs / Icon LDEF / Icon LDEF.c < prev    next >
C/C++ Source or Header  |  1993-11-15  |  3KB  |  111 lines

  1. // File "Icon LDEF.c" - Icon Plotting LDEF Routine that is System 6 and 7 compatible
  2. //   Code is shamelessly based on Apple Snippet by Steven Falkenburg 5/23/91
  3. //   This code is placed in the public domain for free use and distribution! MJS
  4.  
  5. #include <GestaltEqu.h>
  6. #include <Icons.h>
  7.  
  8. // * **************************************************************************** * //
  9. // * **************************************************************************** * //
  10.  
  11. pascal void    main(short message, Boolean hilited, Rect *cellRect, Cell theCell,
  12.         short dataOffset, short dataLen, ListHandle theList) {
  13.     short iconID, hasSys7;
  14.     long response;
  15.     Point drawPt;
  16.     Rect iconRect, textRect;
  17.     RgnHandle iconRgn;
  18.     BitMap iconMap;
  19.     Ptr cellData;
  20.     Handle iconHdl;
  21.     ListPtr theListPtr;
  22.     SignedByte hStateList, hStateCells;
  23.     FontInfo fontInfo;
  24.  
  25.     if (Gestalt(gestaltSystemVersion, &response)) return;
  26.     hasSys7 = (response >= 0x0700);
  27.     
  28.     // Lock down the handles
  29.     hStateList = HGetState((Handle) theList);
  30.     HLock((Handle) theList);
  31.     theListPtr = *theList;
  32.     hStateList = HGetState((Handle) theListPtr->cells);
  33.     HLock((Handle) theListPtr->cells);
  34.     cellData = *(theListPtr->cells);
  35.     
  36.     GetFontInfo(&fontInfo);
  37.     SetRect(&iconRect, cellRect->left + (theListPtr->cellSize.h >> 1) - 16,
  38.             cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) - 16,
  39.             cellRect->left + (theListPtr->cellSize.h >> 1) + 16,
  40.             cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) + 16);
  41.     SetPt(&drawPt, (iconRect.left + iconRect.right) >> 1, 
  42.             iconRect.bottom + fontInfo.ascent + 2);
  43.  
  44.     switch (message) {
  45.         case lInitMsg:
  46.               break;
  47.  
  48.         case lDrawMsg:
  49.             EraseRect(cellRect);
  50.         case lHiliteMsg:
  51.             
  52.               if (dataLen > 0) {
  53.                   if (dataLen >= 2) {
  54.                       BlockMove(cellData + dataOffset, &iconID, sizeof(iconID));
  55.                       if (iconID == 0) EraseRect(&iconRect);
  56.                       else if ((hasSys7 == 0) || PlotIconID(&iconRect, 0,
  57.                             (hilited) ? ttSelected : 0, iconID)) {
  58.                         if (iconHdl = GetResource('ICN#', iconID)) {
  59.                             HLock(iconHdl);
  60.  
  61.                             iconMap.baseAddr = *iconHdl;
  62.                             iconMap.rowBytes = 4;
  63.                             SetRect(&iconMap.bounds,0,0,32,32);
  64.                             CopyBits(&iconMap, &theListPtr->port->portBits,
  65.                                     &iconMap.bounds, &iconRect, srcCopy, 0);
  66.                             
  67.                             if (hilited) {        
  68.                                 iconMap.baseAddr += 128;
  69.                                 CopyBits(&iconMap, &theListPtr->port->portBits,
  70.                                         &iconMap.bounds, &iconRect, srcXor, 0);
  71.                                 }
  72.                                 
  73.                             HUnlock(iconHdl);
  74.                             ReleaseResource(iconHdl);
  75.                             }
  76.                           else EraseRect(&iconRect);
  77.                         }
  78.                       dataLen -= sizeof(iconID);
  79.                       dataOffset += sizeof(iconID);
  80.                       }
  81.                 
  82.                 // Condense if the text doesnt fit
  83.                 if (TextWidth(cellData, dataOffset, dataLen) >
  84.                         (cellRect->right - cellRect->left)) TextFace(condense);
  85.         
  86.                 SetRect(&textRect, drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1) - 2,
  87.                         drawPt.v - fontInfo.ascent - 1,
  88.                         drawPt.h + (TextWidth(cellData, dataOffset, dataLen) >> 1) + 2,
  89.                         drawPt.v + 2);
  90.  
  91.                 EraseRect(&textRect);
  92.                   MoveTo(drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1), drawPt.v);
  93.                 DrawText(cellData, dataOffset, dataLen);
  94.  
  95.                 if (hilited) {            
  96.                       (* (char *) HiliteMode) ^= (1 << hiliteBit);
  97.                       InvertRect(&textRect);
  98.                       }
  99.                   }
  100.         
  101.               break;
  102.  
  103.         case lCloseMsg:
  104.               break;
  105.             }
  106.     
  107.     // Restore the Handles
  108.     HSetState((Handle) theListPtr->cells,hStateCells);
  109.     HSetState((Handle) theList, hStateList);
  110.     }
  111.